<?php
//临时修改内存使用限制，没有限制
ini_set('memory_limit', -1);
$img = imagecreatefromjpeg('li_320_569.jpg');//加载原图
$ww = imagesx($img);
$hh = imagesy($img);

$red = imagecolorallocate($img, 255, 0, 0);
$rr = imagecolorallocatealpha($img, 255, 255, 255, 30);


imageline($img, 0, round($hh / 2), $ww, round($hh / 2), $red);
imageline($img, round($ww / 2), 0, round($ww / 2), $hh, $red);

$size = 15;
$angle = 0;
$x = 10;
$y = 60;
//左上角
$x = 10;
$y = 10 + $size;

//左中
$x = 10;
$y = round($hh / 2) + round($size / 2);

//左下
$x = 10;
$y = $hh - 10;

$font = 'fonts/fzyh.ttf';
$text = '13014577033';

$box = imagettfbbox($size, $angle, $font, $text);
$tw = abs($box[4] - $box[0]);//文本字符串的宽度
//中上
$x = round(($ww - $tw) / 2);
$y = 10 + $size;

//中中
$x = round(($ww - $tw) / 2);
$y = round($hh / 2) + round($size / 2);

//中下
$x = round(($ww - $tw) / 2);
$y = $hh - 10;

//右上
$x = $ww - $tw - 10;
$y = 10 + $size;

//右中
$x = $ww - $tw - 10;
$y = round($hh / 2) + round($size / 2);

//右下
$x = $ww - $tw - 10;
$y = $hh - 10;

//随机位置
$x = mt_rand(10, $ww - $tw - 10);
$y = mt_rand(10 + $size, $hh - 10);


imagettftext($img, $size, $angle, $x, $y, $rr, $font, $text);

header('content-type:image/jpeg');
imagejpeg($img); //直接显示图像添加水印文字后的效果
imagedestroy($img);